package org.jingle.sketch.component
{
	import org.jingle.sketch.Anchor;
	import org.jingle.sketch.event.AnchorDraggedEvent;
	import org.jingle.sketch.event.AnchorEvent;
	
	public class Rectangle extends Composite
	{
		private var _width:Number;
		private var _height:Number;
		private var _roundCorner:Number;
		
		public function Rectangle(parent:Composite, origin:Point, width:Number, height:Number, angle:Number = 0, roundCorner:Number = 0)
		{
			super(parent);
			this.origin = origin;
			_width = width;
			_height = height;
			this.angle = angle; 
			_roundCorner = roundCorner;
		}

		public override function init():void {
			sprite.graphics.clear();
			sprite.graphics.lineStyle(thickness, lineColor, alpha);
			sprite.graphics.beginFill(fillColor, alpha);
			if(_roundCorner > 0){
				sprite.graphics.drawRoundRect(0, 0, _width, _height, _roundCorner, _roundCorner);
			}else{
				sprite.graphics.drawRect(0, 0, width, height);
			}
			sprite.graphics.endFill();
			
			sprite.x = origin.x;
			sprite.y = origin.y;
			sprite.rotation = this.angle;
			super.init();
		}
		
		public override function anchorIt(evt:AnchorEvent):Array {
			var length:Number = Math.sqrt(evt.x * evt.x + evt.y * evt.y);
			
			
			return null;
		}
		
		public override function addDefaultAnchors():void {
			var offset:int = this._height / 2;
			var r:int = 5;
			
			if(offset < 5){
				r = offset;
				offset = 0;
			}
			
			new Anchor(this, new Point(0, offset), Anchor.LEFT_JOIN, r, -10000, 9999 + this.width);
			new Anchor(this, new Point(width, offset), Anchor.LEFT_JOIN, r, 1, 10000);
		}
		
		public function get height():Number {
			return this._height;
		}
		
		public function get width():Number {
			return this._width;
		}
		
		public function get roundCorner():Number {
			return this._roundCorner;
		}
		
		override public function anchorDragged(evt:AnchorDraggedEvent):void {
			var anchor:Anchor = evt.anchor;
			switch (anchor.type){
				case Anchor.LEFT_JOIN:
					
				case Anchor.RIGHT_JOIN:
				case Anchor.UP_JOIN:
				case Anchor.DOWN_JOIN:
				default:
			}
		}
	}
}